package br.ucb.cesbdao.janelas;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.LayoutManager;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.EmptyBorder;

import org.apache.log4j.Logger;

import br.ucb.cesbdao.enuns.EnumLabelAndBotao;
import br.ucb.cesbdao.enuns.EnumTitulo;
import br.ucb.cesbdao.servicos.JanelaUtil;
import br.ucb.cesbdao.servicos.Servicos;

public class DialogFirstConnect extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9086503171321987875L;
	private final JPanel contentPanel = new JPanel();
	private JTextField textField;
	private JPasswordField textField_1;
	static Logger logger = Servicos.carregaLog(DialogFirstConnect.class);

	/**
	 * Create the dialog.
	 */
	public DialogFirstConnect() {
		setTitle(EnumTitulo.TITULO_CONEXAO_BANCO.getTitulo());
		setBounds(100, 100, 364, 241);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		setModal(true);
		contentPanel.setLayout(criaGroupLayout(contentPanel));
	}

	
	@SuppressWarnings("deprecation")
	private LayoutManager criaGroupLayout(JPanel contentPanel) {
		JLabel lblFalhaNaConexao = new JLabel(EnumLabelAndBotao.FALHA_NA_CONEXAO.getTexto());
		lblFalhaNaConexao.setForeground(Color.RED);
		JLabel lblPorFavorInforme = new JLabel(EnumLabelAndBotao.INFORME_DADOS_BANCO.getTexto());
		JLabel lblUsuario = new JLabel(EnumLabelAndBotao.USUARIO.getTexto());
		JLabel lblSenha = new JLabel(EnumLabelAndBotao.SENHA.getTexto());
		textField_1 = new JPasswordField();
		textField_1.setColumns(10);
		textField = new JTextField();
		textField.setColumns(10);
		
		JButton btnOk = new JButton(EnumLabelAndBotao.OK.getTexto());
		btnOk.addActionListener(JanelaUtil.getInstance().dialogFirstConnectionAdicionaActionListener(textField.getText(),textField_1.getText(),this.getClass()));
		
		GroupLayout groupLayout = new GroupLayout(contentPanel);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
					.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addContainerGap()
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING).addComponent(lblUsuario).addComponent(lblSenha)).addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false).addComponent(textField_1).addComponent(textField, GroupLayout.PREFERRED_SIZE, 233, GroupLayout.PREFERRED_SIZE)).addContainerGap(34, Short.MAX_VALUE))
					.addGroup(groupLayout.createSequentialGroup().addContainerGap(152, Short.MAX_VALUE).addComponent(btnOk).addGap(141))
					.addGroup(groupLayout.createSequentialGroup().addContainerGap(45, Short.MAX_VALUE).addComponent(lblPorFavorInforme).addGap(35))
					.addGroup(groupLayout.createSequentialGroup().addContainerGap(53, Short.MAX_VALUE).addComponent(lblFalhaNaConexao).addGap(50))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.TRAILING)
			.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup().addContainerGap().addComponent(lblFalhaNaConexao).addGap(12).addComponent(lblPorFavorInforme).addGap(12)
			.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblUsuario).addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)).addGap(18)
			.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE).addComponent(lblSenha).addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
			.addPreferredGap(ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
			.addComponent(btnOk)
			.addContainerGap())
		);
		return null;
	}
	
}
